package xyz.yq56.easytool.utils.cast;

import java.util.ArrayList;
import java.util.List;

import xyz.yq56.easytool.model.result.ErrorResult;

/**
 * @author yi qiang
 * @date 2023/1/15 12:39
 */
public class CastUtil {

    private CastUtil() {
    }

    /**
     * 强转工具类,减少IDE强制转化警告
     *
     * @param o   对象
     * @param <T> 强转的类
     * @return 强制后的对象
     */
    @SuppressWarnings("unchecked")
    public static <T> T forceCast(Object o) {
        if (o == null) {
            return null;
        }
        return (T) o;
    }

    public static void main(String[] args) {
        ErrorResult result = new ErrorResult();

        List<Object> list = new ArrayList<>();
        list.add(result);

        List<ErrorResult> forceCastList = forceCast(list);
        for (ErrorResult errorResult : forceCastList) {
            errorResult.setDesc("test");
            System.out.println(result);
        }


    }
}
